//
//  InterfaceShare.swift
//  RPay
//
//  Created by Charlie Liao on 2017/6/27.
//  Copyright © 2017年 Charlie. All rights reserved.
//

final class InterfaceShare: NSObject {
    
    static let shared = InterfaceShare()
    
    private override init() { super.init() }
    
    
    // MARK: - Public Method
    
    /// 跳转登录页面
    func pushLoginVC() {
        
        if loginVC == nil {
            loginVC = LoginVC()
        }
        let nav = UINavigationController(rootViewController: loginVC!)
        UIApplication.shared.delegate!.window!!.rootViewController = nav
        tabbarVC = nil
    }
    
    /// 跳转主页面
    func pushTabbarVC() {
        if tabbarVC == nil {
            tabbarVC = UITabBarController()
            
            let homeVC = HomeVC()
            let mVC = MineVC()
            let scVC = ShoppingCartVC()
            let friendVC = RedEnvelopeVC()
            
            var nImg = #imageLiteral(resourceName: "ico_index_normal").renderOriginal()
            var sImg = #imageLiteral(resourceName: "ico_index_press").renderOriginal()

            homeVC.tabBarItem = UITabBarItem(title: LocalStr("首页"), image: nImg, selectedImage: sImg)
            
            nImg = #imageLiteral(resourceName: "hongbao").renderOriginal()
            sImg = #imageLiteral(resourceName: "hongbao_sele").renderOriginal()
            friendVC.tabBarItem = UITabBarItem(title: LocalStr("红包"), image: nImg, selectedImage: sImg)
            
            nImg = #imageLiteral(resourceName: "icon_shopping_normal").renderOriginal()
            sImg = #imageLiteral(resourceName: "icon_shopping_press").renderOriginal()
            scVC.tabBarItem = UITabBarItem(title: LocalStr("购物车"), image: nImg, selectedImage: sImg)
            
            nImg = #imageLiteral(resourceName: "icon_mine_normal").renderOriginal()
            sImg = #imageLiteral(resourceName: "icon_mine_press").renderOriginal()
            mVC.tabBarItem = UITabBarItem(title: LocalStr("我的"), image: nImg, selectedImage: sImg)
            
            let homeNav = UINavigationController(rootViewController: homeVC)
            let friendNav = UINavigationController(rootViewController: friendVC)
            let scNav = UINavigationController(rootViewController: scVC)
            
            let mNav = UINavigationController(rootViewController: mVC)
            
            tabbarVC!.viewControllers = [homeNav,friendNav ,scNav  ,mNav]
        }
        UIApplication.shared.delegate!.window!!.rootViewController = tabbarVC
        loginVC = nil
    }
    
    // MARK: - Get / Set
    
    var tabbarVC: UITabBarController?
    var loginVC: LoginVC?
    var difftime: Int64 = 0
}
